package dao

import (
	"hft/Database/admin"
	"strconv"
	"strings"

	"gorm.io/gorm"
)

type GetBelong struct{}

func (g *GetBelong) GetBelongFromAccount(link string, db *gorm.DB) string {

	var strArr = strings.Split(link, ",")

	if len(strArr) <= 3 {
		return "全国"
	}

	strArr = strArr[2 : len(strArr)-1]

	var ids []int

	for _, v := range strArr {
		id, _ := strconv.Atoi(v)

		ids = append(ids, id)
	}

	var regions []*admin.Region

	db.Find(&regions, ids)

	var belongArr []string

	for _, v := range regions {
		belongArr = append(belongArr, v.Name)
	}

	return strings.Join(belongArr, "-")

}

var GetBelongDao = new(GetBelong)
